package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsYichangMapper;
import net.anzhuo.entity.GsYichang;
import net.anzhuo.service.GsYichangService;

@Service
public class GsYichangServiceImpl implements GsYichangService {

	@Autowired
	private GsYichangMapper gsYichangMapper;

	@Override
	public PaginationVO<GsYichang> getListWithPage(GsYichang gsYichang) {
		PaginationVO<GsYichang> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsYichangMapper.getListWithPage(gsYichang));
		paginationVO.setTotalCount(gsYichangMapper.getCount(gsYichang.getCoMd5()));
		paginationVO.setTotalPage((gsYichangMapper.getCount(gsYichang.getCoMd5()) + gsYichang.getPageSize() -1)  / gsYichang.getPageSize()+1);
		paginationVO.setPageNo(gsYichang.getPageNo());
		return paginationVO;
	}

	@Override
	public GsYichang getById(Long id) {
		return gsYichangMapper.getById(id);
	}

	@Override
	public List<GsYichang> getList() {
		return gsYichangMapper.getList();
	}

	@Override
	public List<GsYichang> getList(GsYichang gsYichang) {
		return gsYichangMapper.getListByQuery(gsYichang);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsYichang gsYichang) {
		gsYichangMapper.update(gsYichang);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsYichang gsYichang) {
		gsYichangMapper.save(gsYichang);
	}

	@Override
	public List<GsYichang> getByMd5(String md5) {
		return  gsYichangMapper.getByMd5(md5);
	}
	
	
	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsYichang gsYichang) {
		gsYichangMapper.delete(gsYichang);
	}
}
